import requests
from  bs4 import BeautifulSoup

url_list= ['http://pic.netbian.com/4kfengjing/']

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36'
}
for x in range(2,5):
    dierye= f'http://pic.netbian.com/4kfengjing/index_{x}.html'
    url_list.append(dierye)
print(url_list)

for url in url_list:
    res = requests.get(url,headers = headers)
    #如果你用。text 获取到的html是乱码，说明request模块默认的编码跟请求的网页编码对不上
    # 使用二进制的方式接收内容，然后用decode（）自己去指定编码方式
    html = res.content.decode('gbk')

    # 1、先创建一个bs这个文件对象
    soup = BeautifulSoup(html,'lxml')
    # print (soup.a.string)
    # print(soup.a['class'])
    a_list =  soup.select('.clearfix li>a')

    for a in a_list:
        src = 'http://pic.netbian.com'+a.img['src']
        img_title = a.b.get_text()
        print(src, img_title)
        response = requests.get(src,headers = headers).content
        with open(f'images/{img_title}.jpg',mode='wb') as f:
            f.write(response)